<template>
    <div>
        <h1>员工添加功能</h1>
        <table class="table">
            <tr>
                <td>名字</td>
                <td><input type="text" v-model="dataa.userName"></td>
            </tr>
            <tr>
                <td>角色</td>
                <td>
                    <select v-model="dataa.userTypeId">
                        <option value="0">请选择</option>
                        <option v-for="a in Bang" :value="a.userTypeId">{{ a.userTypeName }}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>手机号</td>
                <td><input type="text" v-model="dataa.userPhone"></td>
            </tr>
             <tr>
                <td>创建时间</td>
                <td><input type="date"  v-model="dataa.userDateTime"></td>
            </tr>
            <tr>
                <td>状态</td>
                <td>
                    <input type="radio" name="1" :value=true v-model="dataa.userStart">启用
                    <input type="radio" name="1" :value=false v-model="dataa.userStart">禁用
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="button" value="员工添加" @click="Add"></td>
            </tr>
        </table>
    </div>
</template>
<script setup lang="ts">
import {useRouter} from 'vue-router';
import axios from 'axios';
import {ref,onMounted} from 'vue';

const router = useRouter()
onMounted(()=>{
    Bangg()
})

//定义下拉框数组
var Bang=ref({
  userTypeId: 0,
  userTypeName: ""
})

const Bangg=()=>{
    axios.get("/api/UserType/GetAll").then(res=>{
        Bang.value =res.data
    })
}

var dataa = ref({
  id: 0,
  userName: "",
  userTypeId: 0,
  userPhone: "",
  userDateTime: "",
  userStart: false,
  isDelete: false
})

const Add=()=>{

    if(dataa.value.userName=="")
    {
        alert("用户名不能为空")
        return;
    }
    if(dataa.value.userTypeId==0)
    {
        alert("角色不能为空")
        return;
    }
    if(dataa.value.userPhone=="")
    {
        alert("手机号不能为空")
        return;
    }
    if(dataa.value.userDateTime=="")
    {
        alert("时间不能为空")
        return;
    }
    axios.post("/api/User/Add",dataa.value).then(res=>{
        if(res.data>0)
    {
        alert("添加成功")
        router.push("/Show");
    }
    else{
        alert("添加失败")
        return;
    }
    })
}

</script>
<style scoped>
</style>